/*
 * Hus_Button.h
 *
 *  Created on: 2020年3月3日
 *      Author: HpDadi
 */

#ifndef HUS_BUTTON_H_
#define HUS_BUTTON_H_

/*
 * change stm32f1xx.h when your chip is stm32f1xx
 */
#include "stm32f4xx.h"
//#include "stm32f1xx.h"
/*
 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 */

#include "cmsis_os.h"

//if you use Semaphore you should define this
#define __Hus_Button_UseShortSem

typedef enum
{
	Hus_Button_Detected = 0,
	Hus_Button_Comfirmed,
	Hus_Button_Pressed
}Hus_Button_State;

//the Hus_Flag_State may be defined in other .h files, which shows the Flag is true or flase.
#ifndef __Hus_Flag_State
#define __Hus_Flag_State

typedef enum
{
	Hus_Flag_Flase = 0,
	Hus_Flag_True
}Hus_Flag_State;

#endif

#ifndef __Hus_State
#define __Hus_State

typedef enum
{
	Hus_State_Flase = 0,
	Hus_State_True
}Hus_State;

#endif

typedef struct
{
	GPIO_TypeDef* GPIOx;
	uint16_t GPIO_Pin;
	GPIO_PinState ButtonPressed; //decide the low or high when the button is pressed.
	uint8_t DelayTime;  //ms
	uint16_t LongPressPeriods;  //Actual time = DelayTime*LongPressPeriods

	osSemaphoreId_t shortPressedSem;

	//after this will be directly initialized,
	Hus_Button_State hus_button_state;
	//the flags
	Hus_Flag_State shortPressedFlag;
	Hus_Flag_State shortReleasedFlag;
	Hus_Flag_State longPressedFlag;
	Hus_Flag_State longReleasedFlag;
  //decided the Button is really works. default is True,which means it is working.
  Hus_Flag_State buttonOnlineFlag;
}Hus_ButtonDataStruct;


void Hus_ButtonTask(void *pvParameters);
Hus_State Hus_ButtonIfShortPressed(Hus_ButtonDataStruct* buttonDataStructPoint);
Hus_State Hus_ButtonIfLongPressed(Hus_ButtonDataStruct* buttonDataStructPoint);
Hus_State Hus_ButtonIfShortReleased(Hus_ButtonDataStruct* buttonDataStructPoint);
Hus_State Hus_ButtonIfLongReleased(Hus_ButtonDataStruct* buttonDataStructPoint);
osStatus_t Hus_ButtonShortPressedAcquire(Hus_ButtonDataStruct* buttonDataStructPoint, uint32_t timeout);
void Hus_ButtonOnline(Hus_ButtonDataStruct* buttonDataStructPoint);
void Hus_ButtonOffline(Hus_ButtonDataStruct* buttonDataStructPoint);
#endif /* HUS_BUTTON_H_ */
